"""
防盗链的处理
"""
"""
1，拿到contID
2.拿到videoStatus的json -> strURL
3，srcURL里的内容进行修改
4，下载视频
"""
import requests


url = 'https://www.pearvideo.com/video_1753747'
contID = url.split('_')[1]

videosStatus = f'https://www.pearvideo.com/videoStatus.jsp?contId={contID}&mrd=0.9050008821972594'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:100.0) Gecko/20100101 Firefox/100.0',
    # 防盗链 溯源 当前本次请求上一级是谁
    'Referer': 'https://www.pearvideo.com/video_1753747'
}
resp = requests.get(videosStatus, headers=headers)
dic = resp.json()
srcUrl = dic['videoInfo']['videos']['srcUrl']
systemTime = dic['systemTime']
srcUrl = srcUrl.replace(systemTime, f'cont-{contID}')  # 做一个中间的替换

# 下载视频
with open('img/MP4/视频.mp4', 'wb') as f:
    f.write(requests.get(srcUrl).content)
print('下载完毕!!!')